package com.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.config.WXPayConfig;
import com.constant.LocalHostDomainConstant;
import com.emqx.MqttGateway;
import com.emqx.MqttMessageDTO;
import com.exception.ServiceRuntimeException;
import com.github.wxpay.sdk.WXPayUtil;
import com.model.Product;
import com.po.AdvertisementPO;
import com.result.Result;
import com.utils.DateUtil;
import com.utils.RandomUtils;
import com.utils.httpclient.ContentTypeEnum;
import com.utils.httpclient.HttpClientAssisstant;
import com.vo.AdvertisementVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.SortedMap;
import java.util.TreeMap;

@Api(value = "AdvertisementApi")
@CrossOrigin
@RestController
@RequestMapping("/my")
public class MyTestController {




    @Autowired
    private MqttGateway mqttGateway;

    @RequestMapping("/sendMqtt")
    public String sendMqtt(String  sendData){
        Date  now  =new Date();
        MqttMessageDTO msg= new MqttMessageDTO();
        msg.setSendTime(now);
        msg.setMsgIdentifier(DateUtil.getCurrTime());
        msg.setMsgBody("APK_VERSION_UPDATE");
        msg.setMsgReceiver("NeverExistedTopic");
        sendData=JSONObject.toJSONString(msg);
        mqttGateway.sendToMqtt("NeverExistedTopic",sendData);
        mqttGateway.sendToMqtt(sendData,"NeverExistedTopic");
        return "OK";
    }












































    @RequestMapping(value = "/testException", method = RequestMethod.GET)
    public Result<String> testException() {
        Result<String>  result =new Result<String>();
        if(true){
           throw  new ServiceRuntimeException("业务异常");
        }
        return result;
    }


}
